package IO;

import java.io.*;
import java.util.concurrent.Executor;

/**
 * @author wuhan
 * @date 2019/10/12 15:56
 */
class P implements Serializable {
    String name;
    int age;

    public P(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "P{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class ObjectStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        readObj();
    }
    public static void writeObj() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("obj.txt"));
        oos.writeObject(new P("wuhan",1));
        oos.close();
    }
    public static void readObj() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("obj.txt"));
        P p = (P)ois.readObject();
        System.out.println(p);
        ois.close();
    }
}
